<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>03猜数字</title>
</head>
<body>
<button onclick="alert('警告信息')">警告框</button>
<button onclick="confirm('您确定要关闭吗')">确认框</button>
<button onclick="prompt('请输入配对码')">输入框</button>
<hr>
<input type="text" id="i" placeholder="请输入你猜的数字">
<button onclick="f1()">提交</button>
<span id="result"></span>
<script>
    let r = parseInt(Math.random()*100)+1;
  function f1(){

    let guess = parseInt(document.getElementById('i').value);

    console.log(guess);
    let spanE = document.querySelector('#result');
    if(guess = 'NaN'){
        spanE.innerHTML = '请输入1~100的数字';
        return;
    }
    if (guess>r){
      spanE.innerHTML = '猜大了';
    }else if (guess<r){
      spanE.innerHTML = '猜小了';
    }else {
      spanE.innerHTML = '猜对了';
    }
  }

  console.log('答案：'+r);
</script>
</body>
</html>